from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone


class User(AbstractUser):
    gender_choice = (
        (0, '男'),
        (1, '女'),
    )
    occupation_choice = (
        ('administrator', '管理员'),
        ('artist', '艺术家'),
        ('educator', '教育家'),
        ('engineer', '工程师'),
        ('entertainment', '娱乐'),
        ('executive', '行政人员'),
        ('healthcare', '卫生保健'),
        ('homemaker', '家庭主妇'),
        ('lawyer', '律师'),
        ('librarian', '图书管理员'),
        ('marketing', '营销'),
        ('programmer', '程序员'),
        ('salesman', '推销员'),
        ('scientist', '科学家'),
        ('student', '学生'),
        ('technician', '技术员'),
        ('writer', '作家'),
        ('retired', '退休'),
        ('none', '自由人'),
        ('other', '其他'),
    )
    gender = models.BooleanField(choices=gender_choice, blank=True, default=0)
    email = models.EmailField('邮箱', unique=True, error_messages={'unique': "该邮箱已被注册！"})
    date_born = models.DateField(blank=True, default='1990-01-01')
    occupation = models.CharField(max_length=50, choices=occupation_choice, blank=True, default='other')
    is_newcomer = models.BooleanField(default=True)


class Movie(models.Model):
    title = models.CharField(max_length=150, blank=True)
    release_date = models.DateField(blank=True)
    genre = models.CharField(max_length=20, blank=True)
    imdb_url = models.URLField(blank=True)
    poster_url = models.URLField(blank=True)
    is_newcomer = models.BooleanField(default=True)


#两个id外键分别是usr和movie
class Rating(models.Model):
    user_id = models.ForeignKey(User, on_delete=models.CASCADE)
    movie_id = models.ForeignKey(Movie, on_delete=models.CASCADE)
    rating = models.IntegerField(blank=True)
    eval_time = models.DateTimeField(default=timezone.now)


